using Demo2;
using System;

public class App
{
    public static void PrintLine()
    {
        Console.WriteLine("\n================");
    }
    public static void Main()
    {
        Myclass.Message("In Main function.");
        //Test.function1();  //该方法会被标注为过时
        AccessorsTest t = new AccessorsTest();
        t.Name = "3";
        Console.WriteLine(t.Name);

        PrintLine();

        //索引器
        IndexerTest t2 = new IndexerTest();
        t2[0] = "h";
        t2[1] = "e";
        t2[2] = "l";
        t2[3] = "l";
        t2[4] = "o";
        foreach (dynamic k in t2)
        {
            Console.Write(k);
        }
        for (int i = 0; i < 5; i++)
        {
            Console.Write(t2[i]);
        }

        PrintLine();

        //委托
        Console.WriteLine(DelegateTest.Sum(5, 4, delegate(ref int x){  //匿名方法
            x += x;
        }));

        PrintLine();

        //事件
        EventTest t3 = new EventTest();
        t3.handler += new EventTest.NumHandler(delegate (){
            Console.WriteLine("gogo");
        });
        t3.setNum(4);
        t3.setNum(5);

        PrintLine();

        //反射
        Rectangle r = new Rectangle(10f, 20f);
        Type type = typeof(Rectangle);
        foreach (dynamic attr in type.GetCustomAttributes(false))
        {
            DebugInfo dinfo =  attr;
            if (dinfo != null)
            {
                Console.WriteLine("Bug no:{0}\nDeveloper:{1}\nLast Reviewed:{2}", 
                    dinfo.BugNo, dinfo.Developer, dinfo.LastReview);
            }
        }

        Console.ReadKey();
    }
}